package com.example.EatOnTrojans;



import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;

public class Search extends Activity {
	
	int count = 0;
	private ImageView logoBanner;
	private Button searchRest;
	private Spinner spinner;
	private EditText editText;
	private ProgressDialog progressDialog;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search);
        
        logoBanner = (ImageView) findViewById(R.id.banner);
        searchRest = (Button) findViewById(R.id.searchButton);
        spinner = (Spinner) findViewById(R.id.spinner1);
        editText = (EditText) findViewById(R.id.editText1);
        
        
        logoBanner.setOnClickListener(new OnClickListener(){
        	public void onClick(View v){
        		
        		Bundle data = new Bundle();
                Intent intent = new Intent(Search.this,EatOnTrojansActivity.class);
                intent.putExtras(data);
                startActivity(intent);
        	}
        });
        
        searchRest.setOnClickListener(new OnClickListener(){
        	
			public void onClick(View v){
        		
        		String restName = editText.getText().toString();
            	String restType = spinner.getSelectedItem().toString();
            	
            	if(TextUtils.isEmpty(editText.getText())&&restType.equals("none")){
            		String alert = "ALERT: please enter a restaurant name or type";
                	Toast.makeText(getApplicationContext(), alert,Toast.LENGTH_LONG).show();
            	}
            	else if(!TextUtils.isEmpty(editText.getText())&&!restType.equals("none")){
            		String alert = "ALERT: you can only choose ONE search method";
                	Toast.makeText(getApplicationContext(), alert,Toast.LENGTH_LONG).show();
            	}
            	else
            	{
            		progressDialog = new ProgressDialog(Search.this);
            		progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            		progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            		progressDialog.setMessage("Searching...");
            		progressDialog.show();   
            		
            		Bundle data = new Bundle();
            		data.putString("restName", restName);
                    data.putString("restType", restType);
                    Intent intent = new Intent(Search.this,Result.class);
                    intent.putExtras(data);
                    startActivity(intent);
                    
                    
            	}
        	}
        });
    }
}